package org.jeecg.modules.kuner.collectionbase.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.kuner.browsebase.vo.BrowseHisVO;
import org.jeecg.modules.kuner.collectionbase.entity.KrCollectionBase;
import org.jeecg.modules.kuner.collectionbase.service.IKrCollectionBaseService;
import org.jeecg.modules.putil.KrStatic;
import org.jeecg.modules.putil.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description: 收藏记录
 * @Author: jeecg-boot
 * @Date: 2025-02-18
 * @Version: V1.0
 */
@Api(tags = "收藏记录")
@RestController
@RequestMapping("/api/krCollectionBase")
@Slf4j
public class KrCollectionBaseApiController extends JeecgController<KrCollectionBase, IKrCollectionBaseService> {
    @Autowired
    private IKrCollectionBaseService krCollectionBaseService;

    @Resource
    private LoginUserUtil loginUserUtil;

    @ApiOperation(notes = "查询信息的收藏状态，判断岗位的时候传岗位ID，判断简历的时候传简历ID ture代表被收藏", value = "查询信息收藏状态")
    @GetMapping("/collectionStatus/{contentId}")
    public Result<Boolean> collectionStatus(@PathVariable String contentId) {
        boolean exists = krCollectionBaseService.exists(new LambdaQueryWrapper<KrCollectionBase>().eq(KrCollectionBase::getContentId, contentId).eq(KrCollectionBase::getUserId, loginUserUtil.getLoginUser().getId()));
        return Result.OK("查询成功！", exists);
    }

    @GetMapping("/myCollection/{type}")
    @ApiOperation(value = "我的收藏记录", notes = "type 传递CURRICULUM_VITAE查简历 传递HIRE查岗位")
    public Result<IPage<BrowseHisVO>> myBrowse(
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @PathVariable KrStatic.ContentType type
    ) {
        IPage<BrowseHisVO> page = krCollectionBaseService.myCollection(pageNo, pageSize, type);
        return Result.OK("查询成功！", page);
    }
}
